package com.dgh.school.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.dgh.school.bean.Clerk;
import com.dgh.school.common.R;
import com.dgh.school.mapper.ClerkMapper;
import com.dgh.school.service.ClerkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClerkServiceImpl implements ClerkService {

    @Autowired
    private ClerkMapper clerkMapper;

    @Override
    public R selectByPage(int pageNum, int pageSize) throws Exception {

        PageHelper.startPage(pageNum, pageSize);
        // 查询全部数据
        List<Clerk> clerks = clerkMapper.selectAll();
        // 借助分页助手，获得分页信息
        PageInfo<Clerk> pageInfo = new PageInfo<>(clerks);

        return R.ok().setDate("pageInfo", pageInfo);
    }

    @Override
    public void deleteById(int id) throws Exception {
        clerkMapper.deleteById(id);
    }

    @Override
    public void insertData(Clerk clerk) throws Exception {
        clerkMapper.insert(clerk);
    }

    @Override
    public void updateData(Clerk clerk) throws Exception {
        clerkMapper.update(clerk);
    }

    @Override
    public List<Clerk> selectAllClerks() throws Exception {
        List<Clerk> clerks = clerkMapper.selectAll();
        return clerks;
    }

}
